var Report = {

    selected_row_id: null,
    objGrid: null,

    init: function () {
        var self = this;

        self.objGrid = $('#flex').flexigrid({
            colModel: [
                {display: 'Date', width: 200,align: 'center'},
                {display: 'GHS Bill', width: 200,align: 'center'}
                /*{display: 'Acknowledge Payment', width: 60, align: 'center'},
                {display: 'Acknowledge Date', width: 130, align: 'center'}*/
            ],
            height:500,
            subgrid: {
                use: false
            }
        });

        $("#export-btn").click(function () {
            self.print_export_Details('export');
        });
        $("#print-btn").click(function () {
            self.print_export_Details('print');
        });

        $("#start_dt,#end_dt").mask("9999-99-99");

        $(".served-btns").click(function () {
            var r=window.confirm("Are you sure you have served the student ?");
            if (!r){
                return false;
            }
            self.acknowledge_payment($(this).attr('data-id'),$(this));
        });
    },

    print_export_Details: function(data_type){
        $("#print-export-form #data_type").val(data_type);
        $("#print-export-form #data_start_dt").val($("#form-query #start_dt").val());
        $("#print-export-form #data_end_dt").val($("#form-query #end_dt").val());
        $("#print-export-form #data_program_id").val($("#form-query #program_id").val());
        $("#print-export-form #data_section").val($("#form-query #section").val());
        window.open('', "PrintExportWindow", "menubar=yes, width=600, height=500,location=no,status=no,scrollbars=yes,resizable=yes");
        $("#print-export-form").submit();
    },

    acknowledge_payment:function(id,btn){
        var self = this;

        var query = "id="+id;
        var url = $("#acknowledge-payment-url").val();
        $.ajax({
            type: 'post',
            url: url,
            data: query,
            dataType: 'json',
            success: function(data) {
                if(data.code == 0){
                   // $("#reset_modal").modal("hide");
                    alert(data.msg);
                    var parent = btn.parent();
                    parent.html('Yes');
                    //$("#form-query").submit();
                }
                else{
                    alert(data.msg);
                }
                //Results.disableCreditForm(false);

            },
            error: function() {
                //Results.disableCreditForm(false);
            }
        });

    }
};

/* when the page is loaded */
$(document).ready(function () {
    Report.init();
});